package com.chenfan.common.extension.lock;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * 分布式锁异常
 * @author wulg
 * @date 2024/1/19
 */
public class DistributedLockException extends RuntimeException {

    /**
     * 异常类型
     */
    private Type type;

    public DistributedLockException(Type type) {
        this(type, null);
    }

    public DistributedLockException(Type type, String message) {
        super(StringUtils.defaultIfBlank(message, type.getMessage()));
        this.type = type;
    }

    public Type getType() {
        return type;
    }

    @Getter
    @AllArgsConstructor
    public enum Type {
        NOT_CONFIG_DEPEND("DistributedLockTemplate depends on StringRedisTemplate!"),
        NOT_CONFIG_BEAN("DistributedLockTemplate not configured bean!"),
        GET_LOCK_FAIL("Get the Distributed lock failed!"),
        ;

        private String message;

    }
}
